cmake_minimum_required(VERSION 3.12)
project(lvgl VERSION 1.0)

add_compile_options(-std=c99 -D_DEFAULT_SOURCE) 
set(CMAKE_EXE_LINKER_FLAGS "-pthread \
        -lrt -ldl \
        -L/mnt/MyNAS/walker/lvgl_cmake/freetype/INSTALL/lib -lfreetype"
)

link_libraries(${PROJECT_SOURCE_DIR}/freetype/INSTALL/lib/libfreetype.a)

# Configure CCache if available
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
        set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
        set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)

set(LVGL_SDK_PATH ${PROJECT_SOURCE_DIR}/lvgl)
set(LVGL_MAIN_SOURCE ${PROJECT_SOURCE_DIR}/main/src)

include_directories(include ${PROJECT_SOURCE_DIR} 
        ${LVGL_SDK_PATH} 
        "freetype/INSTALL/include/freetype2/"
        "drivers/"
        "display/"
)

file(GLOB_RECURSE INCLUDES "lvgl/src/*.h")
file(GLOB_RECURSE SOURCES "lvgl/src/*.c" "display/*.c" "drivers/*.c")

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

set(CMAKE_CXX_FLAGS "-03")  #设置编译选项

#添加对应的头文件搜索目录
aux_source_directory(${LVGL_SDK_PATH}/../main/src src)
add_executable(main ${src} ${SOURCES} ${INCLUDES})

target_link_libraries(main PRIVATE ${LIB_LIST})

add_custom_target(run COMMAND ${EXECUTABLE_OUTPUT_PATH}/main)
